var util = require('../../utils/util');
var config = require('../../utils/config');
Page({
  data:{
    userName:'',
    classId:0,
    noSave:true
  },
  onLoad:function() {
    var that = this;
    let userInfo = wx.getStorageSync('user');
    that.setData({
      userName: userInfo.userName
    })
  },
  nameinput:function(e) {
    this.setData({      
      userName: e.detail.value,
      noSave:false
    })
  },
  submitName() {
    var that = this;
    let userInfo = wx.getStorageSync('user');
    var options = {
      url: config.clubApi.putUserName,
      method: 'PUT',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        userId: userInfo.userId,
        userName: that.data.userName
      }
    };
    util.request(options, (res, err) => {
      if (res.statusCode===200) {
        util.showSuccess('修改成功!', config.showSuccessTime, () => {
          userInfo.userName = that.data.userName;
          wx.setStorageSync('user', userInfo);
          wx.navigateBack();
        })
      }
    });
  }
})